package com.itheima.service.impl;

import com.itheima.domain.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    @Cacheable(value = "userCache")
    public List<User> findUsers() {
        System.out.println("from mysql select");
        List<User> users = userMapper.findUsers();
        return users;
    }


    @CacheEvict(value = "userCache",allEntries=true)
    @Override
    public void updateUser(User user) {
        System.out.println("from mysql update");
        userMapper.updateUser(user);
    }

}
